package com.authority.framework.config.token;

import com.authority.framework.base.util.ShiroUtils;
import com.authority.framework.base.util.address.HttpUtils;
import com.authority.framework.base.util.laydata.ResultModel;
import com.authority.framework.base.util.laydata.ResultTools;
import com.authority.framework.web.domain.SysUserEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

/**
 * @program: authority
 * @description: 登陆控制层
 * @author: Mr.Yan
 * @create: 2018-11-14 09:39
 **/
@Controller
public class TokenController {


	@RequestMapping("/token")
	@ResponseBody
	@CheckToken
	public ResultModel token(HttpServletRequest request, HttpServletResponse response) throws IOException {
		Map<String,Object> resultMap = new HashMap<>();
		resultMap.put("key","123");
		resultMap.put("key2","456");
		resultMap.put("key3","789");
		return ResultTools.result(0,"",resultMap);
	}


	@RequestMapping("/getToken")
	@ResponseBody
	@CheckToken
	public void getToken(HttpServletRequest request, HttpServletResponse response) throws IOException {
		// 用户
		SysUserEntity subjectUser = ShiroUtils.getSubjectUser();
		//token
		String token = JwtUtil.createJWT(subjectUser.getLoginName(),subjectUser.getPassword());

		String url1 = "http://127.0.0.1/token";
		String url = "http://127.0.0.1:8081/token";
		//String s1 = HttpUtils.sendSSLPost(url1, null);
		//System.out.println("输出结果:————————————————————————" + s1);
		String s = HttpUtils.sendGet(url, null,token);
		System.out.println("输出结果:————————————————————————" + s);

	}

}
